<template>
  <!--评论列表的每一项-->
  <div class="comment-item-box">
    <div class="comment-header">
      <div class="user">{{ item1.user.nickname || '匿名用户' | unameFormat }} {{ item1.created_at }}</div>
      <div class="rate">
        <van-rate v-model="item1.score" allow-half void-icon="star" void-color="#eee" readonly />
      </div>
    </div>
    <div class="comment-content">
      <p>{{ item.content }}</p>
    </div>
    <!-- 图片列表 -->
    <div class="comment-images" @click="show=true">
      <van-image width="100" height="100" :src="image.img" v-for="(image, index) in item1.images" :key="index"/>
    </div>
    <!-- // 图片列表 -->
    <van-image-preview v-model="show" :images="imageUrls" @change="onChange">
      <template v-slot:index>第{{ index + 1 }}页</template>
    </van-image-preview>
  </div>
</template>
<script>
export default {
  props: ['item'],
  data () {
    return {
      item1: this.item,
      value: 5,
      show: false,
      index: 0
    }
  },
  computed: {
    /**
     * 图片大图预览需要处理的数据
     */
    imageUrls () {
      return this.item.images.map(i => i.img)
    }
  },
  methods: {
    onChange (index) {
      this.index = index
    }
  }
}
</script>
<style lang="less">
.comment-item-box {
  padding: 5px 10px;
  border-bottom: 1px solid #f6f6f6;

  .comment-header {
    display: flex;
    justify-content: space-between;

    .user {
      margin-left: 5px;
      font-size: 14px;
    }
  }
  .comment-content {
    color: #616161;
    padding: 5px 0;
    text-align: left;
    font-size: 12px;
    line-height: 2.0;
  }
  .comment-images {
    text-align: left;
    margin-right: 5px;
    .van-image {
      padding: 5px;
    }
  }
}
</style>
